package com.disys.facade;

import java.util.List;

import com.disys.dao.Rec000headerDAO;
import com.disys.model.Rec000header;

public class Rec000headerFacade {

	public Rec000headerFacade() {
	}

	private Rec000headerDAO headerDAO = new Rec000headerDAO();

	public void createHeader(Rec000header header) {
		headerDAO.beginTransaction();
		headerDAO.save(header);
		headerDAO.commit();
	}

	public void updateHeader(Rec000header header) {
		// headerDAO.beginTransaction();
		Rec000header persistedHeader = headerDAO.find(header.getId());
		persistedHeader.setRectype(header.getRectype());
		// headerDAO.commitAndCloseTransaction();
	}

	public Rec000header findheader(int headerId) {
		// headerDAO.beginTransaction();
		Rec000header header = headerDAO.find(headerId);
		// headerDAO.closeTransaction();
		return header;
	}

	public List<Rec000header> listAll() {
		// headerDAO.beginTransaction();
		List<Rec000header> result = headerDAO.findAll();
		// headerDAO.closeTransaction();
		return result;
	}

	public Rec000header findSingleRecord() {

		List<Rec000header> list = null;
		try {
			headerDAO.beginTransaction();
			list = headerDAO.findAll();
			headerDAO.closeTransaction();
		} catch (IllegalStateException ex) {
			list = headerDAO.findAll();
			headerDAO.closeTransaction();
		}
		if (list.size() == 0 || list == null) {
			return null;
		}
		return list.get(0);
	}
}
